//
// Created by win10 on 24-12-11.
//
#include <stdio.h>
//折半查找 ==》二分查找
int binarySearch(int arr[], int size, int key)//size 数据表的长度 key要查找的数据
{
    int low = 0,high=size-1;
    while(low<=high) {
        int mid = (low+high)/2; //中位数
        if(arr[mid] == key) {
            return mid;//找到目标 返回下标
        }
        else if(arr[mid]<key) {
            low = mid+1;//目标值在mid右侧
        }else {
            high = mid-1;//目标值在mid左侧
        }
    }
    return -1;//表示查找失败
}

//递归实现方法
int binarySearchRecursive(int arr[], int low,int high, int key) {
    if(low>high) {
        return -1;//没有查找到===>递归的出口
    }
    int mid = (low+high)/2;
    if(arr[mid] == key) {
        return mid;//查找到出口
    }
    else if(arr[mid]<key) {
        return binarySearchRecursive(arr,mid+1,high,key);
    }else {
        return binarySearchRecursive(arr,low,mid-1,key);
    }
}
//创建一个数组
int main() {
    int arr[]={ 1,3,5,7,9,11,13,15,17,19};
    int size=sizeof(arr)/sizeof(arr[0]);

    int key;
    scanf("%d",&key);

    int index = binarySearch(arr, size, key);
    printf("%d",index);
}